package cn.itheima.service;

import cn.itheima.dao.SectionMapper;
import cn.itheima.domain.Section;
import cn.itheima.utils.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author: cuisensen
 * data: 2018/7/3.
 * time: 13:02.
 */
public class SectionServiceImp implements SectionService {

    @Override
    public List<Section> findSection(String uid) {
        SqlSession session = SqlSessionFactoryUtils.getSession();
        SectionMapper mapper = session.getMapper(SectionMapper.class);
        List<Section> snames = mapper.getSections(uid);
        return snames;
    }

    @Override
    public int insertSection(Section section) {
        SqlSession session = SqlSessionFactoryUtils.getSession();
        SectionMapper mapper = session.getMapper(SectionMapper.class);
        int sid=mapper.insertSection(section);
        section.setSid(sid);
        session.commit();
        return sid;
    }

    @Override
    public Section findSectionBySid(Integer sid) {
        SqlSession session = SqlSessionFactoryUtils.getSession();
        SectionMapper mapper = session.getMapper(SectionMapper.class);
        Section section = mapper.findSectionById(sid);
        return section;
    }
}
